package labox.innovation.gameserver.model.quest;

/**
 * @author Luis Arias; version 2 by Fulminus
 * 
 *         创建：创建任务状态，但追求是没有接受。<br>
 *         开始：玩家已经接受了任务, 任务正在进行中 <br>
 *         完成：已完成的任务。 <br>
 *         所有任务只有这些状态
 * 
 *         This class merely enumerates the three necessary states for all
 *         quests: CREATED: a quest state is created but the quest is not yet
 *         accepted. STARTED: the player has accepted the quest. Quest is
 *         currently in progress COMPLETED: the quest has been completed.
 * 
 *         In addition, this class defines two functions for lookup and inverse
 *         lookup of the state given a name. This is useful only for saving the
 *         state values into the database with a more readable form and then
 *         being able to read the string back and remap them to their correct
 *         states.
 * 
 *         All quests have these and only these states.
 */
public class State {
	public final static byte CREATED = 0;

	public final static byte STARTED = 1;

	/**
	 * 成功:任务成功达到任务目标后任务栏中显示的任务状态
	 */
	public final static byte SUCCEED = 2;

	/**
	 * 失败:任务限制已到,不能按要求完成任务任务栏中显示的任务状态
	 */
	public final static byte FAILURE = 3;

	/**
	 * 完成:任务成功交还以后
	 */
	public final static byte COMPLETED = 4;

	// 解析从数据库读取状态,转换成string
	// discover the string representation of the state, for readable DB storage 
	public static String getStateName(byte state) {
		switch (state) {
		case 1:
			return "Started";
		case 2:
			return "Succeed";
		case 3:
			return "Failure";
		case 4:
			return "Completed";
		default:
			return "Start";
		}
	}

	public static String getStateName_CN(byte state) {
		switch (state) {
		case 1:
			return "进行中";
		case 2:
			return "成功";
		case 3:
			return "失败";
		case 4:
			return "完成";
		default:
			return "创建";
		}
	}

	// 解析string,转换后给数据库
	// discover the state from its string representation (for reconstruction after DB read)
	public static byte getStateId(String statename) {
		if (statename.equals("Started"))
			return 1;
		if (statename.equals("Succeed"))
			return 2;
		if (statename.equals("Failure"))
			return 3;
		if (statename.equals("Completed"))
			return 4;
		return 0;
	}
}
